package com.example.work3;

import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.widget.ViewPager2;


import com.example.work3.Fragment.BlankFragment2;
import com.example.work3.Fragment.BlankFragment3;
import com.example.work3.Fragment.BlankFragment4;

import com.example.work3.Fragment.ViewPageAdapter;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.List;

import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;

public class MainActivity extends AppCompatActivity {

    OkHttpClient okHttpClient = new OkHttpClient();
    private ImageView imagefengcheone;
    private ImageView imagefengchetwo;
    private TabLayout tavlayout;
    private ViewPager2 viewPager2;
    List<Fragment> fragmentList = new ArrayList<>();
    private List<Drawable> icons = new ArrayList<>();

    List<Fragment> fragmentList2;//

    List<String>cityList;//表示需要显示城市的集合

    List<ImageView> imgList;
    String beijing ;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

        Toast.makeText(this, "未登录", Toast.LENGTH_SHORT).show();

        icons.add(getResources().getDrawable(R.drawable.baoxue));

        fragmentList.add(BlankFragment4.newInstance("天气情况"));
        fragmentList.add(BlankFragment2.newInstance("热门城市"));
        fragmentList.add(BlankFragment3.newInstance("个人信息"));



        ViewPageAdapter adapter = new ViewPageAdapter(getSupportFragmentManager(),getLifecycle(),fragmentList,icons);
        viewPager2.setAdapter(adapter);

      /**-------------------------------将Tablayout和ViewgeAdapter滑动效果绑定-------------------------------------------**/
        new TabLayoutMediator(tavlayout, viewPager2, true, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(fragmentList.get(position).getArguments().getString("title"));

            }
        }).attach();
        /**------------------------------------------------------------------------------------------**/
        /**-----------------------------------旋转动画-----------------------------------------------**/
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate);
        imagefengcheone.startAnimation(animation);
        imagefengchetwo.startAnimation(animation);
        /**----------------------------------------------------------------------------------**/
        /**----------------------------------------------------------------------------------**/

        fragmentList2 = new ArrayList<>();
        cityList = new ArrayList<>();
        imgList = new ArrayList<>();




        Bundle bundle = new Bundle();
        bundle.putString("beijing",beijing);
        BlankFragment4 fragment = new BlankFragment4();
        fragment.setArguments(bundle);



    }


    private void initView() {

        imagefengchetwo = (ImageView) findViewById(R.id.imagefengchetwo);
        imagefengcheone = (ImageView) findViewById(R.id.imagefengcheone);
        tavlayout = (TabLayout) findViewById(R.id.tavlayout);
        viewPager2 = (ViewPager2) findViewById(R.id.viewPager2);
    }
}